//
//  HWRegistTypeProtocol.swift
//  HWPromoteProjectAPP
//
//  Created by 王昌健 on 2022/2/7.
//  Copyright © 2022 王昌健. All rights reserved.
//

import UIKit

class HWRegistTypeProtocol: NSObject {
    var model:HWRegistTypeModel?
    var rechargeTypeModel:HWRechargeTypeModel?
    var type:HWMineNavType?
    
}

extension HWRegistTypeProtocol:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        if section == 0 {
            return UIEdgeInsets(top: 0, left: 20*widthScale, bottom: 0, right: 20*widthScale)
        }else {
            return UIEdgeInsets.zero
        }
    }
    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        let  header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "HWHomeHeader", for: indexPath) as! HWHomeHeader
        header.titleLabel.text = "数据"
        header.imageView.image = UIImage(named: "priceRank")
        return header
        
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        if section == 1 {
            return CGSize(width: screenWidth, height: 66*widthScale)
        }else {
            return CGSize.zero
        }
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        if indexPath.section == 0 {
            return CGSize(width: screenWidth-40*widthScale, height: 349*widthScale)
        }else {
            return CGSize(width: (screenWidth - 40*widthScale), height: 46*widthScale)
        }
        
    }
    
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 2
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        if section == 0 {
            return 1
        }
        if type == .registType {
            return (model?.list.count ?? 0) + 1
        }else if type == .rechargeType {
            return (rechargeTypeModel?.list.count ?? 0) + 1
        }else {
            return 0
        }
        
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let registTypePieCell = collectionView.dequeueReusableCell(withReuseIdentifier: "HWRegistTypePieCell", for: indexPath) as! HWRegistTypePieCell
        let registTypeCell = collectionView.dequeueReusableCell(withReuseIdentifier: "HWRegistTypeCell", for: indexPath) as! HWRegistTypeCell
        if indexPath.section == 0 {
            if type == .registType {
                registTypePieCell.model = model
            }else if type == .rechargeType {
                registTypePieCell.rechargeTypeModel = rechargeTypeModel
            }else {
                
            }
            
            return registTypePieCell
        } else {
            if indexPath.row == 0 {
                if type == .registType {
                    registTypeCell.rankLabel.text = "渠道"
                    registTypeCell.userLabel.text = "注册量"
                    registTypeCell.lowUserLabel.text = "占比"
                }else if type == .rechargeType {
                    registTypeCell.rankLabel.text = "渠道"
                    registTypeCell.userLabel.text = "充值金额"
                    registTypeCell.lowUserLabel.text = "占比"
                }else {
                    
                }
                
            }else {
                if type == .registType {
                    registTypeCell.model = model?.list[indexPath.row - 1]
                }else if type == .rechargeType {
                    registTypeCell.rechargeTypeListModel = rechargeTypeModel?.list[indexPath.row - 1]
                }else {
                    
                }
                
            }
            registTypeCell.indexPath = indexPath
            return registTypeCell
        }
    }
}
